<template>
  <div class="avr-introduction">
    <!-- 页面头部 -->
    <div class="page-header">
      <el-page-header @back="goBack" content="自动电压调节器(AVR)原理介绍">
        <template #title>
          <span class="header-title">整流发电机虚拟训练软件</span>
        </template>
        <template #extra>
          <div class="header-actions">
            <el-button type="primary" :icon="Printer" @click="handlePrint"
              >打印</el-button
            >
            <el-button :icon="Download" @click="handleDownload"
              >下载PDF</el-button
            >
          </div>
        </template>
      </el-page-header>
    </div>

    <!-- 内容区域 -->
    <div class="markdown-content">
      <!-- 标题区域 -->
      <h1 class="content-title">自动电压调节器(AVR)原理与结构介绍</h1>

      <!-- 概述部分 -->
      <section class="content-section">
        <h2>1. AVR概述</h2>
        <p>
          自动电压调节器(Automatic Voltage Regulator,
          AVR)是发电机组的核心控制设备，负责监测发电机输出电压并自动调节励磁电流，确保发电机在不同负载条件下保持稳定的输出电压。
        </p>

        <p>
          在十二相整流发电机系统中，AVR通过精确控制励磁机的励磁电流，实现对发电机输出电压的快速、准确调节，保证电力系统的稳定运行。
        </p>

        <p>
          AVR具有响应速度快、调节精度高、可靠性好等特点，是现代发电机组不可或缺的关键部件。
        </p>
      </section>

      <!-- 结构组成 -->
      <section class="content-section">
        <h2>2. AVR结构组成</h2>

        <h3>2.1 硬件组成</h3>
        <p>AVR主要由以下硬件模块组成：</p>

        <el-row :gutter="20">
          <el-col :span="12">
            <div class="component-list">
              <div class="component-item">
                <h4>信号检测模块</h4>
                <ul>
                  <li>电压互感器(PT)：检测发电机输出电压</li>
                  <li>电流互感器(CT)：检测负载电流</li>
                  <li>信号调理电路：对检测信号进行滤波和放大</li>
                </ul>
              </div>

              <div class="component-item">
                <h4>控制处理模块</h4>
                <ul>
                  <li>微处理器：核心控制单元</li>
                  <li>AD转换器：模拟信号转数字信号</li>
                  <li>存储器：存储参数和程序</li>
                </ul>
              </div>

              <div class="component-item">
                <h4>功率输出模块</h4>
                <ul>
                  <li>功率放大器：放大控制信号</li>
                  <li>晶闸管整流电路：控制励磁电流</li>
                  <li>散热装置：确保功率器件正常工作</li>
                </ul>
              </div>
            </div>
          </el-col>

          <el-col :span="12">
            <div class="component-list">
              <div class="component-item">
                <h4>人机接口模块</h4>
                <ul>
                  <li>显示单元：显示电压、电流等参数</li>
                  <li>操作按键：参数设置和功能选择</li>
                  <li>通信接口：与上位机通信</li>
                </ul>
              </div>

              <div class="component-item">
                <h4>电源模块</h4>
                <ul>
                  <li>辅助电源：为AVR提供工作电源</li>
                  <li>电源保护：过压、过流保护电路</li>
                  <li>备用电源：确保断电时安全关机</li>
                </ul>
              </div>

              <div class="component-item">
                <h4>保护功能模块</h4>
                <ul>
                  <li>过压保护：防止电压过高</li>
                  <li>欠压保护：防止电压过低</li>
                  <li>过频/欠频保护：频率异常保护</li>
                </ul>
              </div>
            </div>
          </el-col>
        </el-row>

        <h3>2.2 软件功能</h3>
        <p>AVR的软件系统实现以下核心功能：</p>

        <el-collapse v-model="activeCollapse">
          <p>采用PID控制算法，根据电压偏差实时计算励磁电流调节量。</p>
          <ul>
            <li>比例调节(P)：快速响应电压变化</li>
            <li>积分调节(I)：消除静态误差</li>
            <li>微分调节(D)：提高系统稳定性</li>
          </ul>

          <p>监测发电机运行状态，实现多种保护功能。</p>
          <ul>
            <li>电压异常保护</li>
            <li>频率异常保护</li>
            <li>励磁过流保护</li>
            <li>系统故障诊断</li>
          </ul>

          <p>提供友好的操作界面和通信功能。</p>
          <ul>
            <li>参数显示和设置</li>
            <li>运行状态监控</li>
            <li>故障记录和查询</li>
            <li>远程通信接口</li>
          </ul>
        </el-collapse>
      </section>

      <!-- 工作原理 -->
      <section class="content-section">
        <h2>3. AVR工作原理</h2>

        <h3>3.1 基本工作原理</h3>
        <p>
          AVR通过连续监测发电机输出电压，与设定值进行比较，根据偏差大小和方向自动调节励磁电流，从而维持发电机输出电压的稳定。
        </p>

        <p>
          当负载变化导致发电机电压波动时，AVR能够快速响应，在几十毫秒内完成调节，确保电压稳定在额定值的±1%范围内。
        </p>

        <h3>3.2 工作流程</h3>
        <ol>
          <li>实时检测发电机输出电压和频率</li>
          <li>将检测值与设定值进行比较</li>
          <li>计算电压偏差和变化趋势</li>
          <li>通过PID算法计算励磁电流调节量</li>
          <li>输出控制信号调节励磁机励磁电流</li>
          <li>监测调节效果并进行修正</li>
          <li>实现电压的闭环稳定控制</li>
        </ol>

        <h3>3.3 控制策略</h3>
        <p>AVR采用先进的控制策略确保系统性能：</p>

        <el-row :gutter="16">
          <el-col :span="8">
            <el-card shadow="hover" class="strategy-card">
              <template #header>
                <div class="strategy-header">
                  <el-icon>
                    <TrendCharts />
                  </el-icon>
                  <span>PID控制</span>
                </div>
              </template>
              <div class="strategy-content">
                <p>比例-积分-微分控制，兼顾响应速度和稳定性</p>
              </div>
            </el-card>
          </el-col>

          <el-col :span="8">
            <el-card shadow="hover" class="strategy-card">
              <template #header>
                <div class="strategy-header">
                  <el-icon>
                    <Setting />
                  </el-icon>
                  <span>自适应控制</span>
                </div>
              </template>
              <div class="strategy-content">
                <p>根据运行状态自动调整控制参数</p>
              </div>
            </el-card>
          </el-col>

          <el-col :span="8">
            <el-card shadow="hover" class="strategy-card">
              <template #header>
                <div class="strategy-header">
                  <el-icon>
                    <DataAnalysis />
                  </el-icon>
                  <span>模糊控制</span>
                </div>
              </template>
              <div class="strategy-content">
                <p>处理不确定性和非线性问题</p>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </section>

      <!-- 技术参数 -->
      <section class="content-section">
        <h2>4. 主要技术参数</h2>

        <el-table :data="technicalParams" stripe style="width: 100%">
          <el-table-column
            prop="parameter"
            label="参数名称"
            width="200"
          ></el-table-column>
          <el-table-column
            prop="value"
            label="参数值"
            width="120"
          ></el-table-column>
          <el-table-column
            prop="unit"
            label="单位"
            width="80"
          ></el-table-column>
          <el-table-column prop="description" label="说明"></el-table-column>
        </el-table>

        <h3>4.1 性能指标</h3>
        <p>十二相整流发电机用AVR具有以下卓越性能指标：</p>

        <el-row :gutter="16">
          <el-col :span="6">
            <el-statistic title="调节精度" :value="99.5" suffix="%" />
            <p class="stat-desc">电压稳定精度</p>
          </el-col>
          <el-col :span="6">
            <el-statistic title="响应时间" :value="0.05" suffix="s" />
            <p class="stat-desc">阶跃响应时间</p>
          </el-col>
          <el-col :span="6">
            <el-statistic title="电压调整率" :value="1.0" suffix="%" />
            <p class="stat-desc">空载到满载变化</p>
          </el-col>
          <el-col :span="6">
            <el-statistic title="工作温度" :value="40" suffix="℃" />
            <p class="stat-desc">最高环境温度</p>
          </el-col>
        </el-row>
      </section>

      <!-- 维护与故障处理 -->
      <section class="content-section">
        <h2>5. 维护与故障处理</h2>

        <h3>5.1 日常维护</h3>
        <el-timeline>
          <el-timeline-item timestamp="每日检查" placement="top">
            <el-card>
              <h4>日常检查项目</h4>
              <ul>
                <li>检查AVR显示参数是否正常</li>
                <li>观察电压调节是否稳定</li>
                <li>检查散热风扇运行状态</li>
                <li>记录异常报警信息</li>
              </ul>
            </el-card>
          </el-timeline-item>

          <el-timeline-item timestamp="每月检查" placement="top">
            <el-card>
              <h4>月度维护项目</h4>
              <ul>
                <li>清洁AVR内部灰尘</li>
                <li>检查接线端子紧固情况</li>
                <li>校验电压检测精度</li>
                <li>备份参数设置</li>
              </ul>
            </el-card>
          </el-timeline-item>

          <el-timeline-item timestamp="年度检修" placement="top">
            <el-card>
              <h4>年度检修项目</h4>
              <ul>
                <li>全面性能检测</li>
                <li>更换老化元器件</li>
                <li>软件升级更新</li>
                <li>系统参数优化</li>
              </ul>
            </el-card>
          </el-timeline-item>
        </el-timeline>

        <h3>5.2 常见故障诊断</h3>

        <el-collapse v-model="activeFaults" accordion>
          <el-collapse-item title="电压波动大" name="voltageFluctuation">
            <div class="fault-content">
              <h4>故障现象：</h4>
              <ul>
                <li>发电机输出电压不稳定</li>
                <li>电压表指针摆动明显</li>
                <li>负载设备工作异常</li>
              </ul>

              <h4>可能原因：</h4>
              <ul>
                <li>电压检测回路故障</li>
                <li>PID参数设置不当</li>
                <li>励磁回路接触不良</li>
                <li>AVR硬件故障</li>
              </ul>

              <h4>处理方法：</h4>
              <ol>
                <li>检查电压检测互感器</li>
                <li>重新校准PID参数</li>
                <li>检查励磁回路连接</li>
                <li>更换故障AVR模块</li>
              </ol>
            </div>
          </el-collapse-item>

          <el-collapse-item title="过压保护动作" name="overVoltage">
            <div class="fault-content">
              <h4>故障现象：</h4>
              <ul>
                <li>发电机电压突然升高</li>
                <li>过压保护继电器动作</li>
                <li>系统自动停机</li>
              </ul>

              <h4>可能原因：</h4>
              <ul>
                <li>AVR控制失效</li>
                <li>励磁电流过大</li>
                <li>转速突然升高</li>
                <li>负载突然切除</li>
              </ul>

              <h4>处理方法：</h4>
              <ol>
                <li>检查AVR控制输出</li>
                <li>检测励磁电流值</li>
                <li>检查转速传感器</li>
                <li>分析负载变化情况</li>
              </ol>
            </div>
          </el-collapse-item>

          <el-collapse-item title="AVR无输出" name="noOutput">
            <div class="fault-content">
              <h4>故障现象：</h4>
              <ul>
                <li>AVR无控制信号输出</li>
                <li>发电机无法建立电压</li>
                <li>励磁电流为零</li>
              </ul>

              <h4>可能原因：</h4>
              <ul>
                <li>AVR电源故障</li>
                <li>控制板损坏</li>
                <li>程序运行异常</li>
                <li>通信故障</li>
              </ul>

              <h4>处理方法：</h4>
              <ol>
                <li>检查AVR供电电源</li>
                <li>重启AVR系统</li>
                <li>检查控制板状态</li>
                <li>联系专业人员维修</li>
              </ol>
            </div>
          </el-collapse-item>
        </el-collapse>
      </section>

      <!-- 参数设置与调试 -->
      <section class="content-section">
        <h2>6. 参数设置与调试</h2>

        <h3>6.1 基本参数设置</h3>
        <el-table :data="parameterSettings" stripe style="width: 100%">
          <el-table-column
            prop="parameter"
            label="参数名称"
            width="200"
          ></el-table-column>
          <el-table-column
            prop="range"
            label="设置范围"
            width="150"
          ></el-table-column>
          <el-table-column
            prop="default"
            label="默认值"
            width="100"
          ></el-table-column>
          <el-table-column prop="description" label="说明"></el-table-column>
        </el-table>

        <h3>6.2 调试步骤</h3>
        <el-steps :active="debugActive" finish-status="success" align-center>
          <el-step title="初始检查" description="检查接线和电源" />
          <el-step title="空载调试" description="空载状态下调整电压" />
          <el-step title="负载调试" description="带负载调试稳定性" />
          <el-step title="参数优化" description="优化PID参数" />
          <el-step title="验收测试" description="全面性能测试" />
        </el-steps>

        <div class="debug-control">
          <el-button @click="prevDebug" :disabled="debugActive <= 1"
            >上一步</el-button
          >
          <el-button
            type="primary"
            @click="nextDebug"
            :disabled="debugActive >= 5"
            >下一步</el-button
          >
        </div>
      </section>

      <!-- 相关知识链接 -->
      <section class="content-section">
        <h2>7. 相关知识链接</h2>

        <div class="knowledge-links">
          <el-card
            v-for="link in relatedLinks"
            :key="link.title"
            class="link-card"
            @click="navigateTo(link.path)"
          >
            <template #header>
              <div class="card-header">
                <el-icon>
                  <Connection />
                </el-icon>
                <span>{{ link.title }}</span>
              </div>
            </template>
            <div class="card-content">
              <p>{{ link.description }}</p>
              <div class="card-actions">
                <el-tag :type="link.type" size="small">{{
                  link.category
                }}</el-tag>
              </div>
            </div>
          </el-card>
        </div>
      </section>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import {
  Printer,
  Download,
  Connection,
  TrendCharts,
  Setting,
  DataAnalysis,
} from "@element-plus/icons-vue";

const router = useRouter();
const activeCollapse = ref(["controlAlgorithm"]);
const activeFaults = ref(["voltageFluctuation"]);
const debugActive = ref(1);

// 技术参数数据
const technicalParams = ref([
  {
    parameter: "额定工作电压",
    value: "110",
    unit: "V",
    description: "AVR控制回路工作电压",
  },
  {
    parameter: "电压调节范围",
    value: "±10",
    unit: "%",
    description: "输出电压可调节范围",
  },
  {
    parameter: "调节精度",
    value: "±1",
    unit: "%",
    description: "稳态电压调节精度",
  },
  {
    parameter: "响应时间",
    value: "0.05",
    unit: "s",
    description: "阶跃负载响应时间",
  },
  {
    parameter: "工作温度",
    value: "-20~40",
    unit: "℃",
    description: "环境工作温度范围",
  },
  {
    parameter: "防护等级",
    value: "IP54",
    unit: "",
    description: "防尘防水等级",
  },
  {
    parameter: "通信接口",
    value: "RS485",
    unit: "",
    description: "标准通信接口",
  },
  {
    parameter: "绝缘电阻",
    value: "100",
    unit: "MΩ",
    description: "输入输出端绝缘电阻",
  },
]);

// 参数设置数据
const parameterSettings = ref([
  {
    parameter: "电压设定值",
    range: "90%~110%",
    default: "100%",
    description: "发电机输出电压设定值",
  },
  {
    parameter: "比例增益(Kp)",
    range: "0.1~10.0",
    default: "2.5",
    description: "PID控制比例系数",
  },
  {
    parameter: "积分时间(Ti)",
    range: "0.1~10.0s",
    default: "1.0s",
    description: "PID控制积分时间常数",
  },
  {
    parameter: "微分时间(Td)",
    range: "0~1.0s",
    default: "0.1s",
    description: "PID控制微分时间常数",
  },
  {
    parameter: "软启动时间",
    range: "1~30s",
    default: "5s",
    description: "电压建立软启动时间",
  },
  {
    parameter: "过压保护值",
    range: "105%~120%",
    default: "110%",
    description: "过电压保护动作值",
  },
]);

// 相关知识链接
const relatedLinks = ref([
  {
    title: "励磁机原理",
    description: "了解AVR如何控制励磁机工作",
    path: "/principle/exciter",
    category: "励磁系统",
    type: "primary",
  },
  {
    title: "副励磁机原理",
    description: "学习副励磁机为AVR提供电源的原理",
    path: "/principle/pilot-exciter",
    category: "电源系统",
    type: "success",
  },
  {
    title: "旋转整流器",
    description: "了解励磁电流的整流过程",
    path: "/principle/rotating-rectifier",
    category: "电力电子",
    type: "warning",
  },
  {
    title: "发电机组控制",
    description: "掌握完整的发电机组控制系统",
    path: "/principle/control-panel",
    category: "控制系统",
    type: "danger",
  },
]);

const goBack = () => {
  router.push("/home");
};

const handlePrint = () => {
  window.print();
};

const handleDownload = () => {
  console.log("下载AVR原理介绍PDF");
};

const navigateTo = (path) => {
  router.push(path);
};

const nextDebug = () => {
  if (debugActive.value < 5) {
    debugActive.value++;
  }
};

const prevDebug = () => {
  if (debugActive.value > 1) {
    debugActive.value--;
  }
};
</script>

<style scoped>
.avr-introduction {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 24px;
  background-color: #fff;
  padding: 16px;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.header-title {
  font-size: 18px;
  font-weight: bold;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.markdown-content {
  background-color: #fff;
  padding: 24px;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.content-title {
  font-size: 28px;
  color: #303133;
  text-align: center;
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 2px solid #409eff;
}

.content-section {
  margin-bottom: 40px;
}

.content-section h2 {
  font-size: 22px;
  color: #303133;
  margin-bottom: 16px;
  padding-left: 8px;
  border-left: 4px solid #409eff;
}

.content-section h3 {
  font-size: 18px;
  color: #606266;
  margin: 16px 0 12px 0;
}

.content-section h4 {
  font-size: 16px;
  color: #909399;
  margin: 12px 0 8px 0;
}

.content-section p {
  line-height: 1.6;
  color: #606266;
  margin-bottom: 16px;
}

.content-section ul,
.content-section ol {
  padding-left: 24px;
  margin-bottom: 16px;
}

.content-section li {
  line-height: 1.6;
  color: #606266;
  margin-bottom: 8px;
}

/* 组件列表样式 */
.component-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.component-item {
  background-color: #f8f9fa;
  padding: 16px;
  border-radius: 4px;
  border-left: 4px solid #409eff;
}
</style>